<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
</head>
<body>
<%@ page import="cs236369.hw5.InitListener" %>
<%@ page import="cs236369.hw5.DBConnection" %>
<%@ page import="cs236369.hw5.User" %>
<%@ page import="java.util.ArrayList" %>

<%
	String admin = (String)session.getAttribute("admin");
	if(admin == null) { // user is not an admin
		response.sendRedirect(request.getContextPath() + InitListener.welcomePage);
		return;
	}
	ArrayList<User> users = DBConnection.getAllUsers();
%>
<div class="text">
<p class="subtitle">Manage users</p>
<table id="adminTable" class="adminTable">
<tr class="title"><td>username</td><td>name</td><td>email</td><td>admin</td><td>delete</td></tr>
<%
	int row = 1;
	for(User user : users) {
		out.print("<tr class=\"data\">");
		out.print("<td>" + user.getUserName() + "</td>");
		out.print("<td>" + user.getFirstName() + " " + user.getLastName() + "</td>");
		out.print("<td>" + user.getEmail() + "</td>");
		String isAdmin = user.isAdmin() == true ? "yes" : "no";
		out.print("<td>" + isAdmin + "</td>");
		out.println("<td><input type=\"button\" class=\"regularButton\" value=\"Delete\" id=\"delCell" + row +
				"\" onclick=\"delUser(" + row + ", \'" + user.getUserName() + "\')\"></input></td></tr>");
		row++;
	}
%>
</table></div>
</body>
</html>